package com.lovo.csc.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.DirectExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.rabbit.connection.CachingConnectionFactory;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;


@Configuration
public class RabbitConfig {
    @Autowired
    CachingConnectionFactory connectionFactory;

    //rabbitmq模板
    @Bean(value = "rabbitTemplate")
    public RabbitTemplate rabbitTemplate() {
        return new RabbitTemplate(connectionFactory);
    }
    //创建冻结状态交换机
//    @Bean
//    public DirectExchange directFreezeExchange() {
//        return new DirectExchange("cscFreezeUser");
//    }
//    //创建冻结状态队列
//    @Bean
//    public Queue queueFreeze() {
//        return new Queue("queueFreeze");
//    }
//
//    //绑定冻结状态交换机和冻结状态队列
//    @Bean
//    public Binding directFreezeExchangeToQueueFreeze(@Qualifier("directFreezeExchange") DirectExchange cscFreezeUser, Queue queueFreeze) {
//        return BindingBuilder.bind(queueFreeze).to(cscFreezeUser).with("rabbit.freeze");
//    }


    //创建审核交换机
    @Bean
    public DirectExchange directOrderExchange() {
        return new DirectExchange("Csc_Two");
    }

    //创建审核供应商交换机
    @Bean
    public DirectExchange directRFpExchange(){
        return new DirectExchange("directRFpExchange");
    }
    //创建采购供应商交换机
    @Bean
    public DirectExchange directCaiGouExchange(){
        return new DirectExchange("directCaiGouExchange");
    }

    //创建审核不通过队列
    @Bean
    public Queue queueAuditCscTwo() {
        return new Queue("queueAuditCscTwo");
    }

    //创建审核供应商队列
    @Bean
    public Queue queueRFp(){
        return new Queue("queueRFp");
    }

    //创建采购供应商队列
    @Bean
    public Queue queueCaiGou(){
        return new Queue("queueCaiGou");
    }

    //创建审核交换机和审核不通过队列进行绑定
    @Bean
    public Binding directOrderExchangeToQueueOrder(@Qualifier("directOrderExchange") DirectExchange Csc_Two, Queue queueAuditCscTwo) {
        return BindingBuilder.bind(queueAuditCscTwo).to(Csc_Two).with("rabbit.Csc");
    }

    //创建审核供应商交换机和队列进行绑定
    @Bean
    public Binding directRFpExchangeToQueueRFp(DirectExchange directRFpExchange,Queue queueRFp){
        return BindingBuilder.bind(queueRFp).to(directRFpExchange).with("rabbit.RFp");
    }

    //创建采购供应商交换机和队列进行绑定
    @Bean
    public Binding directCaiGouExchangeToQueueCaiGou(DirectExchange directCaiGouExchange,Queue queueCaiGou){
        return BindingBuilder.bind(queueCaiGou).to(directCaiGouExchange).with("rabbit.CaiGou");
    }

}